package com.gnerv.author.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gnerv.author.entity.Config;
import com.gnerv.author.mapper.ConfigMapper;
import com.gnerv.author.service.IConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 博客平台-配置表 服务实现类
 * </p>
 *
 * @author Gnerv LiGen
 * @since 2019-07-15
 */
@Service
public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config> implements IConfigService {

    @Autowired
    ConfigMapper configMapper;

    @Override
    public boolean createConfig(Config config) {
        return true;
    }

    @Override
    public boolean deleteConfig(String bId) {
        return true;
    }

    @Override
    public boolean updateConfig(Config config) {
        configMapper.update(config, new QueryWrapper<>(new Config(config.getbId())));
        return true;
    }

    @Override
    public boolean updateConfig(String blogName, String blogLogo, String realmName) {
        return false;
    }

    @Override
    public Config selectConfig(String bId) {
        return null;
    }

    @Override
    public Map<String, Object> listConfig(Config config) {
        List<Config> configs = configMapper.selectList(new QueryWrapper<>(config));
        Map<String, Object> map = new HashMap<>(8);
        for (Config c : configs) {
            map.put(c.getCode(), c);
        }
        return map;
    }
}
